package com.secret.manager.service.impl;

import com.secret.core.constant.AESConstant;
import com.secret.dao.entity.UserLogin;
import com.secret.dao.mapper.UserLoginMapper;
import com.secret.manager.aes.MyAESUtil;
import com.secret.manager.service.UserLoginService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
@Service
public class UserLoginServiceImpl implements UserLoginService {
    @Resource
    private UserLoginMapper userLoginMapper;
    @Resource
    private MyAESUtil  myAESUtil;
    @Resource
    private UserLogin userLogin;
    @Override
    @ApiModelProperty("用户服务效验")
    public UserLogin effect(String openId) throws Exception{
        //前端openid解密
       String voOpenId=myAESUtil.Decrypt(openId, AESConstant.AES_KEY_VO);
       //数据库openid加密
       String  mysqlOpenId=myAESUtil.Encrypt(voOpenId,AESConstant.AES_KEY_DB);
       userLogin=userLoginMapper.selectOneByOpenId(mysqlOpenId);
       //解密用户openId
        userLogin.setUserOpenId(myAESUtil.Decrypt(userLogin.getUserOpenId(), AESConstant.AES_KEY_DB));
        return userLogin;
    }
}
